package com.haois.mp.database.module.person.controller;

import cn.zhouyafeng.itchat4j.api.WechatTools;
import com.haois.mp.database.commom.constant.Reply;
import com.haois.mp.database.commom.enums.ApiResultEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description
 *
 * @author RuiHaoZ on GuangZhou
 * @date 2019/2/23 17:35
 */
@RestController
@RequestMapping("/person")
public class MessageToolController {

    @PostMapping("/wechat/msg/send/user")
    public Reply sendMsgPerson(String msg, String toUserName) {
        toUserName = WechatTools.getUserNameByNickName(toUserName);
        if (StringUtils.isNotBlank(toUserName)){
            WechatTools.sendMsgByUserName(msg, toUserName);
            return new Reply(ApiResultEnum.API_00,"发送成功");
        }else {
            return new Reply(ApiResultEnum.API_10,"未找到对应目标");
        }
    }
    @PostMapping("/wechat/msg/send/group")
    public Reply sendMsgGroup(String msg, String toUserName) {
        toUserName = WechatTools.getGroupUserNameByNickName(toUserName);
        if (StringUtils.isNotBlank(toUserName)){
            WechatTools.sendMsgByUserName(msg, toUserName);
            return new Reply(ApiResultEnum.API_00,"发送成功");
        }else {
            return new Reply(ApiResultEnum.API_10,"未找到对应目标");
        }

    }
}
